package hulkpop;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;

/**
 *
 * @author Aderthad
 */
public class Hulkpop {

    /**
     * @param args the command line arguments
     */
    private static final File folder = new File("e:\\Temp\\");

    private static final String[] prefixes = new String[]{
        "[HULKPOP.COM][Single]",
        "[HULKPOP.COM][Mini Album]",
        "[HULKPOP.COM][Compalition]",
        "[HULKPOP.COM][Album]",
        "[HULKPOP.COM]",};

    public static void main(String[] args) throws IOException {

        Files.walkFileTree(folder.toPath(), new FileVisitor<Path>() {

            @Override
            public FileVisitResult preVisitDirectory(Path t, BasicFileAttributes bfa) throws IOException {
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFile(Path t, BasicFileAttributes bfa) throws IOException {
                handle(t.toFile());
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFileFailed(Path t, IOException ioe) throws IOException {
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult postVisitDirectory(Path t, IOException ioe) throws IOException {
                handle(t.toFile());
                return FileVisitResult.CONTINUE;
            }
        });
    }

    private static void handle(File file) {
        if(file.getName().endsWith(".url")){
            file.delete();
            return;
        }
        file.renameTo(new File(file.getParentFile().getAbsolutePath() + File.separator + rename(file.getName())));
    }

    private static String rename(String name) {
        for (String s : prefixes) {
            if (name.startsWith(s)) {
                return name.substring(s.length()).trim();
            }
        }
        return name;
    }
}
